<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <style>
        .adminInfo {
            position: relative;
            left: 35%;
            font-size: 18px;
            padding-top: 5%;
        }

        .row {
            padding-bottom: 20px;
        }

        .lb {
            font-weight: normal;
        }

        #btn1 {
            position: relative;
            top: 0px;
            left: 90px;
        }

        #btn2 {
            position: relative;
            top: 0px;
            left: 115px;
        }
    </style>

    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" th:href="@{/res/css/amazeui.min.css}"/>
    <link rel="stylesheet" th:href="@{/res/layui/css/layui.css}"/>
    <link rel="stylesheet" th:href="@{/res/css/admin.css}"/>

    <script type="text/javascript" th:src="@{/js/jquery-1.11.3.min.js}"></script>
</head>

<body>
<div class="admin-content-body">
    <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">修改密码</strong>
            <small></small>
        </div>
    </div>

    <hr>

    <div class="adminInfo">
        <div class="inputName">
            <div class="row"><label class="lb">旧&nbsp;&nbsp;密&nbsp;&nbsp;码:</label><input type="password" id="pw1"
                                                                                          value=""></div>

            <div class="row"><label class="lb">新&nbsp;&nbsp;密&nbsp;&nbsp;码:</label><input type="password" id="pw2"
                                                                                          value=""></div>

            <div class="row"><label class="lb">确认密码:</label><input type="password" id="pw3" value=""></div>
            <div>
                <button class="am-btn am-btn-primary" id="btn1" onclick="confirm()">确认</button>
                <button class="am-btn am-btn-primary" id="btn2" onclick="cancel()">取消</button>
            </div>
        </div>
    </div>
</div>

<script>
    //id从url得到
    var result = new Object();
    result = getParameter();
    var uid = result["uid"];

    function confirm() {
        var opw = document.getElementById("pw1").value;
        var npw1 = document.getElementById("pw2").value;
        var npw2 = document.getElementById("pw3").value;
        $.ajax({
            type: 'post',
            url: '/admin/updatePwd',
            data: {id: uid, opw: opw, npw1: npw1, npw2: npw2},
            dataType: 'text',
            success: function (mydata) {
                alert(mydata);
            },
            error: function () {
                alert("请求失败!");
            }
        });
        close();
    }

    function cancel() {
        close();
    }

    //关闭弹窗页面
    function close() {
        window.parent.location.reload();
    }

    //解析url传值
    function getParameter() {
        var url = location.search;//获取url?后面的内容
        var result = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                result[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
            }
        }
        return result;
    }
</script>
</body>
</html>